<?php

namespace addons\shopro\controller;

use addons\shopro\service\lucky\LuckyService;
use addons\shopro\service\tokens\PledgelogService;
use addons\shopro\service\tokens\TradeService;
use addons\shopro\service\user\UserAuth;

class Autotask extends Common
{

    protected $noNeedLogin = ['*'];

    public function _initialize()
    {
        parent::_initialize();

        if (!$this->request->isCli()) {
            $this->error('非法操作！');
        }
    }

    //质押结算
    public function pledgeFinish()
    {
        if(sheep_config('shop.basic.pledge')=='0')
        {
            print('质押结算已关闭');
        }else{

            print((new PledgelogService())->finish());
        }
    }

    //检查未充值和未推荐的上锁
    public function lockUser()
    {
        print((new UserAuth())->autoLock());
    }


    //交易中心挂卖72小时无交易自动下架
    public function noTradeCloseOrder()
    {
        print((new TradeService())->autoCloseTrade());
    }


    public function openLucky()
    {
        if(sheep_config('shop.basic.order')=='0')
        {
            print('订单处理已关闭');
        }else{

            print((new LuckyService())->openLucky());
        }


    }

    public function updateData()
    {
        $model=new LuckyService();
        $model->updateDayData();

        if(sheep_config('shop.basic.release')=='0')
        {
            print('贡献值释放已关闭');

        }else{
            $model->updateTokens();


        }


    }
    

    public function toMoney()
    {
        $model=new LuckyService();
        $model->updateUserAgent();
    }

    public function toOrder()
    {
        $model=new LuckyService();
        $model->updataScore();
    }

    public function autoLucky()
    {
        \think\Queue::push('\addons\shopro\job\Commission@autoLucky',[], 'shopro');

    }

    public function autoOpen()
    {
        $model=new LuckyService();

        $model->autoOpen(1);

    }

    public function autoClose()
    {
        $model=new LuckyService();

        $model->autoOpen(0);

    }

}